from core.support import set_cutscene
from core.item import Item
from core.action import Action
from items.keys import Keys

#gun code
#from util.sessions import Session

class Gun(Item):
    def __init__(self):
        Item.__init__(self, "gun")    # do basic initialization for every item
        self.has_gun = True
        
#gun code
        #session = Session()
        #session['gun'] = self.has_gun

                
        # build list of actions
        self.add_action(ShootGun)
    
    
    def get_description(self):
            return "AKM assault rifle"

# define actions for this item

class ShootGun(Action):
    def __init__(self):
        Action.__init__(self, "shoot_gun")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Shoot rifle"
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "post"
    
    # only works in basement. add cutscene
    def do_action(self,game,room,request):
        if self.item.has_gun:
            if room.get_id() == 'livingquarters':
                if room.enemy_alive:
                    set_cutscene("You shoot the intruder's weapons out of his hands and promptly take him hostage.")
                    self.item.has_gun = False
                    room.enemy_alive = False
                    room.add_item(Keys())
            else:
                set_cutscene("Harmlessly yet still startling, bullets ricochet off one of the room's walls.")
                self.item.has_gun = False
        else:
            set_cutscene("You pull the trigger, but there is no ammunition left.")
        return